home *** CD-ROM | disk | FTP | other *** search
-
- #include <XtcLib.h>
- #include <XtcElements.h>
- #include <XtcMessages.h>
-
- #include "config.h"
- #include "rc.h"
- #include "MacMud.h"
- #include "mac.h"
-
- #include ":console:ed.h"
- #include ":console:buffer.h"
- #include ":console:command.h"
-
- #include <sys/types.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include "comm.h"
-
- #define KBUFFSIZE 4096
- #define kLEFTSPACE 4
-
- extern int cb_append(cmdbuf *cb);
-
- typedef struct TConsole {
- short penx;
- short currx;
- UI_ViewPtr view;
- Boolean caretHidden;
- Boolean caretVisible;
- Boolean consoleActive;
- ulong caretTime;
- uchar inbuffer[KBUFFSIZE + 1];
- uchar outbuffer[KBUFFSIZE + 1];
- short incount;
- short outcount;
- int topoffset;
- Rect bounds;
- cmdbuf *cb;
- char *tmpfname;
- } TConsole, *TConsolePtr, **TConsoleHdl;
-
- extern Boolean gRunning; // Defined in MacMud.c
- extern Boolean gBackgroundOnly; // Defined in MacMud.c
- extern long gMudResponseFactor; // Defined in <mac.h>
- extern short gMudLibVolRef; // Defined in <mac.h>
- extern long gMudLibDirID; // Defined in <mac.h>
-
- pascal Boolean XtcDebug(UI_ViewPtr view, UI_Action *action);
- pascal Boolean XtcConsole(UI_ViewPtr view, UI_Action *action);
- pascal Boolean XtcMain(UI_ViewPtr view, UI_Action *action);
-
- /********************************************************************
- * #defines... should probably be in header file... *
- *********************************************************************/
- #define TRUE 1
- #define FALSE 0
- #define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LoWrd(aLong) ((aLong) & 0xFFFF)
-
- static int debugLog;
- static int tempCount = 0;
- static RgnHandle updateRgn = NULL;
- static UI_ViewPtr debugView = NULL;
- extern int __write(int fildes, char* buf, unsigned long nbyte);
-
- pascal Boolean SFEmptyFileFilter(ParmBlkPtr paramBlock)
- {
- #pragma unused(paramBlock)
- return true;
- }
-
- static Boolean gDirSemaphore = false;
-
- pascal short SFDirectoryDlgHook(short item, DialogPtr theDialog)
- {
- #pragma unused(theDialog)
-
- const short kCancel = 3;
- const short kDirButton = 11;
-
- if (item == kDirButton) {
- gDirSemaphore = true;
- return kCancel;
- } else return item;
- }
-
- Boolean ChangeMudlibDir(long *dirID, short *volRef)
- {
- Point thePt;
- SFReply theReply;
- SFTypeList typeList;
- const short kDirDlg = 4002;
-
- SetPt(&thePt, 0, 0);
- gDirSemaphore = false;
- SFPGetFile(thePt, "\p", SFEmptyFileFilter, 0, &typeList,
- SFDirectoryDlgHook, &theReply, kDirDlg, NULL);
- if (gDirSemaphore) {
- *dirID = (*(long *)0x398);
- *volRef = -(*(short *)0x0214);
- return true;
- }
- return false;
- }
-
- void InitConsole()
- {
- debugView = NULL;
- if (!gBackgroundOnly) {
- debugView = UI_LoadView(kDebugView);
- if (debugView == NULL)
- LPExit(1);
- UI_OpenView(debugView);
- }
- debugLog = open("console.log",O_CREAT+O_RDWR+O_TRUNC);
- if (!gBackgroundOnly) {
- if (debugLog == -1) {
- fprintf(stdout,"Couldn't open \"console.log\".\n");
- fflush(stdout);
- }
- }
- }
-
- void CloseConsole()
- {
- if (debugLog != -1) {
- close(debugLog);
- debugLog = -1;
- }
- if (debugView) {
- UI_DestructView(debugView);
- }
- }
-
- UI_ViewPtr DoGetWindow(struct interactive *ip)
- {
- UI_ViewPtr theView;
-
- theView = UI_LoadView(kConsoleView);
- if (theView) {
- UI_OpenView(theView);
- ((UI_ViewPeek)theView)->viewRef = (long)ip;
- }
- return theView;
- }
-
- void DoDisposeWindow(UI_ViewPtr view)
- {
- UI_DestructView(view);
- }
-
- static void DoConsoleDrawCaret(TConsoleHdl hConsole)
- {
- Rect util;
- FontInfo info;
- short starty;
- short height;
- Rect bounds;
- cmdbuf *cb;
- PenState penState;
-
- GetPenState(&penState);
- PenMode(patXor);
-
- PenPat(&qd.black);
-
- TextFont(monaco);
- TextSize(9);
- GetFontInfo(&info);
- cb = (*hConsole)->cb;
- bounds = (*hConsole)->bounds;
- starty = info.ascent + info.leading;
- height = info.ascent + info.descent + info.leading;
- util.bottom = height * (cb->first - (*hConsole)->topoffset + 1);
- util.top = util.bottom - height - 1;
- util.left = (*hConsole)->penx;
- util.right = util.left + info.widMax;
- PaintRect(&util);
- SetPenState(&penState);
-
- (*hConsole)->caretVisible = !(*hConsole)->caretVisible;
- }
-
- static void DoConsoleShowCaret(TConsoleHdl hConsole)
- {
- if (!(*hConsole)->consoleActive)
- return;
- if ((*hConsole)->caretHidden) {
- // if (!(*hConsole)->caretVisible)
- // DoConsoleDrawCaret(hConsole);
- (*hConsole)->caretHidden = false;
- (*hConsole)->caretTime = TickCount() + GetCaretTime();
- }
- }
-
- static void DoConsoleHideCaret(TConsoleHdl hConsole)
- {
- if (!(*hConsole)->consoleActive)
- return;
- if (!(*hConsole)->caretHidden) {
- if ((*hConsole)->caretVisible)
- DoConsoleDrawCaret(hConsole);
- (*hConsole)->caretHidden = true;
- (*hConsole)->caretTime = 0;
- }
- }
-
- static void DoConsoleActivate(TConsoleHdl hConsole)
- {
- if (!(*hConsole)->consoleActive) {
- (*hConsole)->consoleActive = true;
- DoConsoleShowCaret(hConsole);
- }
- }
-
- static void DoConsoleDeactivate(TConsoleHdl hConsole)
- {
- if ((*hConsole)->consoleActive) {
- DoConsoleHideCaret(hConsole);
- (*hConsole)->consoleActive = false;
- }
- }
-
- static void DoConsoleIdle(TConsoleHdl hConsole)
- {
- long ticks;
-
- if (!(*hConsole)->consoleActive)
- return;
- if (!(*hConsole)->caretHidden &&
- (ticks = TickCount()) >= (*hConsole)->caretTime)
- {
- DoConsoleDrawCaret(hConsole);
- (*hConsole)->caretTime = ticks + GetCaretTime();
- }
- }
-
- static short _starty;
- static short _height;
- static short _linenum;
- static Rect _bounds;
- static FontInfo _finfo;
-
- static void DoConsoleDrawLine(char *text)
- {
- short i;
- short x;
- short len;
- short currx;
- short start;
-
- i = 0;
- len = strlen(text);
-
- start = _starty + _height * _linenum;
- if (start > _bounds.bottom)
- return;
- MoveTo(_bounds.left, start);
- while (i < len) {
- start = i;
- while (i < len && text[i] != 9)
- i++;
- if (i < len && text[i] == 9) {
- if (i > start) {
- DrawText(text + start, 0, i-start-1);
- }
- currx = i-1;
- for (x = 0; x <= currx % 8; x++, currx++)
- DrawChar(' ');
- i += 1;
- } else {
- DrawText(text + start, 0, i-start);
- }
- }
- _linenum += 1;
- }
-
- static void DoConsoleUpdate(TConsoleHdl hConsole, int topoffset, Boolean doHide)
- {
- cmdbuf *cb;
-
- cb = (*hConsole)->cb;
- if (!cb->first)
- return;
- TextFont(monaco);
- TextSize(9);
- GetFontInfo(&_finfo);
- _bounds = (*hConsole)->bounds;
- _linenum = 0;
- _starty = _bounds.top + _finfo.ascent + _finfo.leading;
- _height = _finfo.ascent + _finfo.descent + _finfo.leading;
- if (doHide)
- DoConsoleHideCaret(hConsole);
- topoffset = (topoffset == -1) ? (*hConsole)->topoffset : topoffset;
- eb_range(cb->edbuf, 1 + topoffset, cb->first, DoConsoleDrawLine, FALSE);
- if ((*hConsole)->outcount) {
- (*hConsole)->outbuffer[(*hConsole)->outcount] = '\0';
- DoConsoleDrawLine((*hConsole)->outbuffer);
- }
- if (doHide)
- DoConsoleShowCaret(hConsole);
- }
-
- void DoConsoleScroll(UI_ViewPtr view, short h, short v)
- {
- Rect r;
- short height;
- FontInfo theFont;
- TConsoleHdl hConsole;
-
- r.left = 0;
- r.top = 0;
- r.right = view->portRect.right - 15;
- r.bottom = view->portRect.bottom - 15;
- if (updateRgn == NULL)
- updateRgn = NewRgn();
- GetFontInfo(&theFont);
- height = theFont.ascent + theFont.descent + theFont.leading;
- ScrollRect(&r, -h, -v * height, updateRgn);
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- DoConsoleUpdate(hConsole, UI_GetVScrollValue(view), false);
- }
-
- void TrackScrollBar(UI_ViewPtr view, short code)
- {
- short delta;
- short height;
- short pageSize;
- short currValue;
- FontInfo theFont;
-
- GetFontInfo(&theFont);
- height = theFont.ascent + theFont.descent + theFont.leading;
- pageSize = (view->portRect.bottom - view->portRect.top - 15) / height;
- currValue = UI_GetVScrollValue(view);
- if (code == inUpButton) {
- delta = -1;
- } else if (code == inDownButton) {
- delta = 1;
- } else if (code == inPageUp) {
- delta = -pageSize / 2;
- } else if (code == inPageDown) {
- delta = pageSize / 2;
- } else return;
-
- if (delta > 0) {
- if (currValue == UI_GetVScrollMax(view))
- return;
- if (currValue + delta > UI_GetVScrollMax(view)) {
- delta = UI_GetVScrollMax(view) - currValue;
- }
- } else if (delta < 0) {
- if (currValue == UI_GetVScrollMin(view))
- return;
- if (currValue + delta < UI_GetVScrollMin(view)) {
- delta = -currValue;
- }
- }
- UI_SetVScrollValue(view, currValue + delta);
-
- DoConsoleScroll(view, 0, delta);
- }
-
- static void DoConsoleKey(TConsoleHdl hConsole, char c)
- {
- int i;
- Point pen;
- FontInfo info;
- Rect util;
- short penx;
- short currx;
- short starty;
- short height;
- Rect bounds;
- short value;
- cmdbuf *cb;
-
- value = UI_GetVScrollValue((*hConsole)->view);
- if ((*hConsole)->topoffset != value)
- {
- UI_SetVScrollValue((*hConsole)->view, (*hConsole)->topoffset);
- DoConsoleScroll((*hConsole)->view, 0, (*hConsole)->topoffset - value);
- }
-
- TextFont(monaco);
- TextSize(9);
- GetFontInfo(&info);
- penx = (*hConsole)->penx;
- currx = (*hConsole)->currx;
- bounds = (*hConsole)->bounds;
- starty = info.ascent + info.leading;
- height = info.ascent + info.descent + info.leading;
-
- cb = (*hConsole)->cb;
- DoConsoleHideCaret(hConsole);
- MoveTo(penx, starty + height * (cb->first - (*hConsole)->topoffset));
- switch(c)
- {
- case 0:
- return;
-
- case '\n':
- if (updateRgn == NULL)
- updateRgn = NewRgn();
- if ((bounds.bottom - bounds.top) / height <=
- cb->first - (*hConsole)->topoffset + 1)
- {
- ScrollRect(&bounds, 0, -height, updateRgn);
- util.bottom = bounds.bottom;
- util.top = bounds.bottom - height;
- util.left = bounds.left;
- util.right = bounds.right;
- EraseRect(&util);
- (*hConsole)->topoffset += 1;
- }
- currx = 0;
- (*hConsole)->outbuffer[(*hConsole)->outcount] = '\0';
- if (!ec_push()) {
- cb_append(cb);
- addblock(cb, (*hConsole)->outbuffer);
- endblock(cb);
- ec_pop();
- cb->first += 1;
- }
- (*hConsole)->outcount = 0;
- DoConsoleUpdate(hConsole, -1, true);
- MoveTo(bounds.left, starty + height *
- (cb->first - (*hConsole)->topoffset));
- lb_inact(cb->edbuf->lb);
- if ((*hConsole)->topoffset !=
- UI_GetVScrollMax((*hConsole)->view))
- {
- UI_NoScrollUpdate = true;
- UI_SetVScrollMax((*hConsole)->view, (*hConsole)->topoffset);
- UI_SetVScrollValue((*hConsole)->view, (*hConsole)->topoffset);
- }
- break;
-
- case 7: /* BEL */
- SysBeep(1);
- break;
-
- case 8: /* DEL */
- if (!currx)
- break;
- Move(-info.widMax, 0);
- util.bottom = starty + height *
- (cb->first - (*hConsole)->topoffset);
- util.top = util.bottom - height;
- util.left = penx - info.widMax;
- util.right = penx;
- EraseRect(&util);
- currx -= 1;
- if ((*hConsole)->outcount)
- (*hConsole)->outcount -= 1;
- break;
-
- case 9: /* TAB */
- for (i = 0; i <= currx % 8; i++, currx++)
- DrawChar(' ');
- (*hConsole)->outbuffer[(*hConsole)->outcount++] = c;
- break;
-
- default:
- if(c > 31) {
- DrawChar(c);
- (*hConsole)->outbuffer[(*hConsole)->outcount++] = c;
- currx++;
- }
- }
- GetPen(&pen);
- (*hConsole)->penx = pen.h;
- (*hConsole)->currx = currx;
- DoConsoleShowCaret(hConsole);
- }
-
- pascal Boolean XtcDebug(UI_ViewPtr view, UI_Action *action)
- {
- switch (action->what)
- {
- case UIA_PreOpenView:
- {
- cmdbuf *cb;
- char *tmpfname;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)NewHandleClear(sizeof(TConsole));
- tmpfname = NewPtr(20);
- sprintf(tmpfname, "tmp0%05d", tempCount++);
- cb = cb_new(tmpfname);
- cb->this = 0;
- cb_append(cb);
- (*hConsole)->cb = cb;
- (*hConsole)->view = view;
- (*hConsole)->tmpfname = tmpfname;
- ((UI_ViewPeek)view)->viewAux = (long)hConsole;
- return true;
- }
- case UIA_OpenView:
- {
- Rect bounds;
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- TextFont(monaco);
- TextSize(9);
- bounds = view->portRect;
- bounds.left += kLEFTSPACE;
- bounds.right -= 15;
- bounds.bottom -= 15;
- (*hConsole)->bounds = bounds;
- (*hConsole)->penx = bounds.left;
- SetPort(savePort);
- return true;
- }
- case UIA_DestructView:
- {
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- cb_del((*hConsole)->cb);
- DisposPtr((*hConsole)->tmpfname);
- DisposHandle((Handle)hConsole);
- return true;
- }
- case UIA_MouseDown:
- {
- Point thePt;
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- thePt = action->event.where;
- GlobalToLocal(&thePt);
- // DoConsoleClick(hED, thePt);
- SetPort(savePort);
- return true;
- }
- case UIA_PostUpdate:
- {
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- DoConsoleUpdate(hConsole, -1, true);
- SetPort(savePort);
- return true;
- }
- case UIA_TrackMouseInVScroll:
- {
- Rect r;
- Point pt;
- short value;
- RgnHandle theRgn;
- RgnHandle saveClip;
-
- if (action->code == inThumb) {
- short code;
- UI_ViewHeaderHdl viewHdl;
-
- pt = action->event.where;
- GlobalToLocal(&pt);
-
- viewHdl = ((UI_ViewPeek)view)->viewHdl;
- value = UI_GetVScrollValue(view);
- code = TrackControl((*viewHdl)->windowVScroll, pt, NULL);
- if (!code)
- return true;
- }
- r.top = 0;
- r.left = 0;
- r.bottom = view->portRect.bottom - 15;
- r.right = view->portRect.right - 15;
- theRgn = NewRgn();
- saveClip = NewRgn();
- GetClip(saveClip);
- RectRgn(view->clipRgn, &r);
- if (action->code == inThumb) {
- DoConsoleScroll(view, 0, UI_GetVScrollValue(view) - value);
- } else if (action->code == inUpButton) {
- TrackScrollBar(view, action->code);
- } else if (action->code == inDownButton) {
- TrackScrollBar(view, action->code);
- } else if (action->code == inPageUp) {
- TrackScrollBar(view, action->code);
- } else if (action->code == inPageDown) {
- TrackScrollBar(view, action->code);
- }
- SetClip(saveClip);
- DisposeRgn(saveClip);
- DisposeRgn(theRgn);
- return true;
- }
- case UIA_Activate:
- {
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- DoConsoleActivate(hConsole);
- SetPort(savePort);
- return true;
- }
- case UIA_Deactivate:
- {
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- DoConsoleDeactivate(hConsole);
- SetPort(savePort);
- return true;
- }
- }
- return XtcMain(view, action);
- }
-
- pascal Boolean XtcConsole(UI_ViewPtr view, UI_Action *action)
- {
- switch (action->what)
- {
- case UIA_PreOpenView:
- {
- cmdbuf *cb;
- char *tmpfname;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)NewHandleClear(sizeof(TConsole));
- tmpfname = NewPtr(20);
- sprintf(tmpfname, "tmp0%05d", tempCount++);
- cb = cb_new(tmpfname);
- cb->this = 0;
- cb_append(cb);
- (*hConsole)->cb = cb;
- (*hConsole)->view = view;
- (*hConsole)->tmpfname = tmpfname;
- ((UI_ViewPeek)view)->viewAux = (long)hConsole;
- return true;
- }
- case UIA_OpenView:
- {
- Rect bounds;
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- bounds = view->portRect;
- bounds.left += kLEFTSPACE;
- bounds.right -= 15;
- bounds.bottom -= 15;
- (*hConsole)->bounds = bounds;
- (*hConsole)->penx = bounds.left;
- SetPort(savePort);
- return true;
- }
- case UIA_DestructView:
- {
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- cb_del((*hConsole)->cb);
- DisposPtr((*hConsole)->tmpfname);
- DisposHandle((Handle)hConsole);
- return true;
- }
- case UIA_MouseDown:
- {
- Point thePt;
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- thePt = action->event.where;
- GlobalToLocal(&thePt);
- // DoConsoleClick(hConsole, thePt);
- SetPort(savePort);
- return true;
- }
- case UIA_KeyDown:
- case UIA_AutoKey:
- {
- GrafPtr savePort;
- TConsoleHdl hConsole;
- struct interactive *ip;
- char key = action->event.message & charCodeMask;
-
- if (action->event.modifiers & cmdKey)
- return true;
- ip = (struct interactive *)((UI_ViewPeek)view)->viewRef;
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- if ((*hConsole)->incount >= KBUFFSIZE)
- return true;
- GetPort(&savePort);
- SetPort(view);
- if (!ip->noecho) {
- DoConsoleKey(hConsole, key);
- }
- (*hConsole)->inbuffer[(*hConsole)->incount++] = key;
- SetPort(savePort);
- return true;
- }
- case UIA_PostUpdate:
- {
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- DoConsoleUpdate(hConsole, -1, true);
- SetPort(savePort);
- return true;
- }
- case UIA_TrackMouseInVScroll:
- {
- Rect r;
- Point pt;
- short value;
- RgnHandle theRgn;
- RgnHandle saveClip;
-
- if (action->code == inThumb) {
- short code;
- UI_ViewHeaderHdl viewHdl;
-
- pt = action->event.where;
- GlobalToLocal(&pt);
-
- viewHdl = ((UI_ViewPeek)view)->viewHdl;
- value = UI_GetVScrollValue(view);
- code = TrackControl((*viewHdl)->windowVScroll, pt, NULL);
- if (!code)
- return true;
- }
- r.top = 0;
- r.left = 0;
- r.bottom = view->portRect.bottom - 15;
- r.right = view->portRect.right - 15;
- theRgn = NewRgn();
- saveClip = NewRgn();
- GetClip(saveClip);
- RectRgn(view->clipRgn, &r);
- if (action->code == inThumb) {
- DoConsoleScroll(view, 0, UI_GetVScrollValue(view) - value);
- } else if (action->code == inUpButton) {
- TrackScrollBar(view, action->code);
- } else if (action->code == inDownButton) {
- TrackScrollBar(view, action->code);
- } else if (action->code == inPageUp) {
- TrackScrollBar(view, action->code);
- } else if (action->code == inPageDown) {
- TrackScrollBar(view, action->code);
- }
- SetClip(saveClip);
- DisposeRgn(saveClip);
- DisposeRgn(theRgn);
- return true;
- }
- case UIA_Activate:
- {
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- DoConsoleActivate(hConsole);
- SetPort(savePort);
- return true;
- }
- case UIA_Deactivate:
- {
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- DoConsoleDeactivate(hConsole);
- SetPort(savePort);
- return true;
- }
- case UIA_Timer:
- {
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- GetPort(&savePort);
- SetPort(view);
- DoConsoleIdle(hConsole);
- SetPort(savePort);
- return true;
- }
- }
- return XtcMain(view, action);
- }
-
- int DoWindowRead(struct interactive *ip)
- {
- UI_ViewPtr view;
- TConsoleHdl hConsole;
-
- if (!ip)
- return -1;
- view = (UI_ViewPtr)(ip->window);
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- if ((*hConsole)->incount) {
- return (*hConsole)->inbuffer[--(*hConsole)->incount];
- }
- return -1;
- }
-
- int DoWindowWrite(struct interactive *ip,
- const char *buf, unsigned long nbyte)
- {
- int i;
- int tab;
- FontInfo info;
- Boolean flushed;
- UI_ViewPtr view;
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- if (!ip)
- return -1;
- view = (UI_ViewPtr)(ip->window);
- GetPort(&savePort);
- SetPort(view);
- GetFontInfo(&info);
- flushed = (nbyte == 0);
- hConsole = (TConsoleHdl)((UI_ViewPeek)view)->viewAux;
- for(i = 0; i < nbyte; i++) {
- if (*buf == '\n') {
- flushed = true;
- DoConsoleKey(hConsole, *buf);
- } else if ((*hConsole)->outcount < KBUFFSIZE) {
- flushed = false;
- if (*buf == 8 && (*hConsole)->currx) {
- (*hConsole)->currx -= 1;
- (*hConsole)->penx -= info.widMax;
- if ((*hConsole)->outcount)
- (*hConsole)->outcount -= 1;
- } else if (*buf == 9) {
- for (tab = 0; tab <= (*hConsole)->currx % 8; tab++, (*hConsole)->currx++)
- (*hConsole)->penx += info.widMax;
- (*hConsole)->outbuffer[(*hConsole)->outcount++] = *buf;
- } else if (*buf > 31) {
- (*hConsole)->outbuffer[(*hConsole)->outcount++] = *buf;
- (*hConsole)->currx += 1;
- (*hConsole)->penx += info.widMax;
- }
- }
- buf += 1;
- }
- if (!flushed) {
- DoConsoleUpdate(hConsole, -1, true);
- }
- SetPort(savePort);
- return nbyte;
- }
-
- int write(int fildes, const char* buf, unsigned long nbyte)
- {
- int i;
- int tab;
- FontInfo info;
- Boolean flushed;
- GrafPtr savePort;
- TConsoleHdl hConsole;
-
- if (fildes < 0 || fildes >2)
- return __write(fildes, buf, nbyte);
-
- if (debugLog != -1)
- __write(debugLog, buf, nbyte);
- if (!debugView)
- return nbyte;
- GetPort(&savePort);
- SetPort(debugView);
- GetFontInfo(&info);
- flushed = (nbyte == 0);
- hConsole = (TConsoleHdl)((UI_ViewPeek)debugView)->viewAux;
- for(i = 0; i < nbyte; i++) {
- if (*buf == '\n') {
- flushed = true;
- DoConsoleKey(hConsole, *buf);
- } else if ((*hConsole)->outcount < KBUFFSIZE) {
- flushed = false;
- if (*buf == 8 && (*hConsole)->currx) {
- (*hConsole)->currx -= 1;
- (*hConsole)->penx -= info.widMax;
- if ((*hConsole)->outcount)
- (*hConsole)->outcount -= 1;
- } else if (*buf == 9) {
- for (tab = 0; tab <= (*hConsole)->currx % 8; tab++, (*hConsole)->currx++)
- (*hConsole)->penx += info.widMax;
- (*hConsole)->outbuffer[(*hConsole)->outcount++] = *buf;
- } else if (*buf > 31) {
- (*hConsole)->outbuffer[(*hConsole)->outcount++] = *buf;
- (*hConsole)->currx += 1;
- (*hConsole)->penx += info.widMax;
- }
- }
- buf += 1;
- }
- if (!flushed) {
- DoConsoleUpdate(hConsole, -1, true);
- }
- SetPort(savePort);
- return nbyte;
- }
-